package com.zllkj.mm.adapter

import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.zllkj.mm.R
import com.zllkj.mm.module.goods.vm.ItemCollectionsVM
import com.zllkj.mm.module.goods.vm.ItemNearByShopGoodsVM
import com.zllkj.mm.util.common.PictureLoadUtil

class NearByShopGoodsListAdapter(layoutResId: Int, data: List<ItemNearByShopGoodsVM?>?) :
        BaseQuickAdapter<ItemNearByShopGoodsVM, BaseViewHolder>(layoutResId, data) {
    override fun convert(baseViewHolder: BaseViewHolder, vm: ItemNearByShopGoodsVM) {
        baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_shopname).text = vm.shopName
        baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_unit_price).text = vm.unitPrice
        baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_name).text = vm.goodsName
        baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_sale_count).text = "已经售出"+ vm.saleCount
        PictureLoadUtil.loadPic(baseViewHolder.getView(R.id.iv_near_by_shop_goods_image),vm.picUrl)
        baseViewHolder.addOnClickListener(R.id.tv_near_by_shop_add_to_shoppingcart)
        baseViewHolder.addOnClickListener(R.id.tv_near_by_shop_goods_shopname)

        if (vm.isAd) {
            baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_shopname).visibility = View.GONE
            baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_unit_price).visibility = View.GONE
            baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_name).visibility = View.GONE
            baseViewHolder.getView<AppCompatTextView>(R.id.tv_near_by_shop_goods_sale_count).visibility = View.GONE
            baseViewHolder.getView<AppCompatImageView>(R.id.tv_near_by_shop_add_to_shoppingcart).visibility = View.GONE

        }


        if (getParentPosition(vm) % 2 ==0) {
            baseViewHolder.getView<CardView>(R.id.card_view).layoutParams = ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,450)
        } else {
            baseViewHolder.getView<CardView>(R.id.card_view).layoutParams = ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,550)
        }
    }
}